<?php
namespace App\Api\Exceptions;

use App\Api\ErrCode;
use ClassesWithParents\E;

/**
 * api通用异常
 *
 * 功能
 *
 * 2018年4月27日 上午9:58:06
 *
 * @category PHP
 * @package B2C
 * @author lijian <lij25@mingyuanyun.com>
 * @copyright 2018 Mingyuanyun
 * @version 1.0.0
 */
class ApiCommonException extends \RuntimeException
{
    static public function randomIsEmpty()
    {
        return new self('random不能为空', ErrCode::COMMON_RANDOM_IS_EMPTY);
    }

    static public function randomLengthErr()
    {
        return new self('random长度错误(8-20位)', ErrCode::COMMON_RANDOM_LENGTH_ERR);
    }

    static public function timestampIsEmpty()
    {
        return new self('timestamp为空', ErrCode::COMMON_TIMESTAMP_EMPTY);
    }

    static public function timestampOvertime()
    {
        return new self('timestamp过期', ErrCode::COMMON_TIMESTAMP_OVERTIME);
    }

    static public function timestampOverdue()
    {
        return new self('timestamp超期', ErrCode::COMMON_TIMESTAMP_OVERDUE);
    }

    static public function signIsEmpty()
    {
        return new self('sign为空', ErrCode::COMMON_SIGN_EMPTY);
    }

    static public function dataIsEmpty()
    {
        return new self('数据为空', ErrCode::COMMON_DATA_EMPTY);
    }

    static public function signCheckFail($msg = null)
    {
        return new self('sign验证失败' . $msg, ErrCode::COMMON_SIGN_CHECK_FAIL);
    }

    static public function needLogin()
    {
        return new self('需要登录', ErrCode::COMMON_NEED_LOGIN);
    }

    static public function loginError()
    {
        return new self('用户名或密码不正确', ErrCode::COMMON_LOGIN_ERROR);
    }

    static public function loginAuth()
    {
        return new self('用户权限不足', ErrCode::COMMON_LOGIN_AUTH);
    }

    static public function loginInvalidCredentials()
    {
        return new self('token无效', ErrCode::COMMON_LOGIN_INVALID_CREDENTIALS);
    }

    static public function requestParamsErr($errMsg = '请求参数错误')
    {
        return new self($errMsg, ErrCode::COMMON_REQUEST_PARAMS_ERR);
    }

    static public function youTuApiErr($error_code = ErrCode::YOU_TU_API_EXCEPTION_ERR)
    {
        $err_msg = "腾讯优图接口未知异常";
        $you_tu_err = config('youtu.err');
        if (isset($you_tu_err[$error_code]) && !empty($you_tu_err[$error_code])) {
            $err_msg = $you_tu_err[$error_code];
        }
        return new self($err_msg, ErrCode::YOU_TU_API_EXCEPTION_ERR);
    }

    static public function youTuMultiFaceIdentifyErr()
    {
        return new self('人脸检索失败', ErrCode::YOU_TU_API_MULTI_FACE_IDENTIFY_ERR);
    }

    static public function youTuFaceVerifyErr()
    {
        return new self('人脸验证失败', ErrCode::YOU_TU_API_FACE_VERIFY_ERR);
    }

    static function faceVerifyErr()
    {
        return new self('人脸验证用户不存在', ErrCode::FACE_VERIFY_ERR);
    }

    static public function faceNewPersonErr($client_name = '')
    {
        return new self('人脸图片'.$client_name.'不符合要求', ErrCode::FACE_NEW_PERSON_ERR);
    }

    static public function meetingSignInNotBeginning()
    {
        return new self('会议签到未开始', ErrCode::MEETING_SIGN_IN_NOT_BEGINNING);
    }

    static public function meetingSignInIsFinished()
    {
        return new self('会议签到已结束', ErrCode::MEETING_SIGN_IN_IS_FINISHED);
    }

    static public function meetingSignInIsEmpty()
    {
        return new self('签到会议数据为空', ErrCode::MEETING_SIGN_IN_IS_EMPTY);
    }
}
